package com.hskn.hss.app.tlemergentplan.controller;


import com.hskn.hss.app.tlemergentplan.service.APPITlEmergentPlanService;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.alarmcar.entity.AlarmCar;
import com.hskn.hss.module.outstorageCfg.mapper.TlOutStorageCfgMapper;
import com.hskn.hss.module.tlemergentopera.entity.TlEmergentPlanOperadetails;
import com.hskn.hss.module.tlemergentplan.entity.TlEmergentPlan;
import com.hskn.hss.module.tlemergentplan.mapper.TlEmergentPlanMapper;
import com.hskn.hss.module.userdepart.entity.SysUserDepart;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-18
 */
@Api(tags = {"-tl_emergent_plan"}, description = "APP应急计划")
@Slf4j
@RestController
@RequestMapping("/hss/app/tlemergentplan")
public class APPTlEmergentPlanController {
    @Autowired
    APPITlEmergentPlanService tlEmergentPlanService;


    @RequestMapping(value = "getSelectList", method = RequestMethod.POST)
    public AjaxResult<Object> getSelectList(@RequestBody @Validated TlEmergentPlan tlEmergentPlan) {

        return AjaxResult.success(tlEmergentPlanService.getSelectList( tlEmergentPlan));
    }

    @RequestMapping(value = "getDetail", method = RequestMethod.POST)
    public AjaxResult<Object> getDetail(@RequestBody @Validated TlEmergentPlan tlEmergentPlan,HttpServletRequest request) {

        try {
            tlEmergentPlan = tlEmergentPlanService.getDetail(tlEmergentPlan);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(tlEmergentPlan);

    }

    @RequestMapping(value = "getList", method = RequestMethod.POST)
    public AjaxResult<Object> getList(@RequestBody @Validated TlEmergentPlan tlEmergentPlan) {
        try {
            return AjaxResult.success(tlEmergentPlanService.getList(tlEmergentPlan));
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "emergentPlanCalendar", method = RequestMethod.POST)
    public AjaxResult<Object> emergentPlanCalendar() {
        try {
            return AjaxResult.success(tlEmergentPlanService.emergentPlan());
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.INSERT, tableName = "tl_emergent_plan", bean = TlEmergentPlan.class, beanMapper = TlEmergentPlanMapper.class, names = "planname")
    @RequestMapping(value = "audit", method = RequestMethod.POST)
    public AjaxResult<Object> audit(@RequestBody @Validated TlEmergentPlanOperadetails tlEmergentPlanOperadetails) {
        try {
            return tlEmergentPlanService.audit(tlEmergentPlanOperadetails);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }
}

